package insulinpumpsimulation.com.his.audiocontrol;

import java.io.FileInputStream;
import java.io.IOException;
import sun.audio.AudioData;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import sun.audio.ContinuousAudioDataStream;

/**
 *
 * @author Sabahul and Arun
 */

public class SoundAlert {
    private static String File;
    public static boolean control_alarm_value = false;
    AudioPlayer MGP= AudioPlayer.player;
    AudioStream BGM;
    AudioData MD;
    ContinuousAudioDataStream loop = null;
    
     public SoundAlert(String file) {
         this.File=file;
     }
     
     public void SetAudio(String file) {
         this.File=file;
     }
     
     public void start(){
       try {
            // Open an audio input stream.
            BGM = new AudioStream(new FileInputStream(File));
            MD=BGM.getData();
            loop=new ContinuousAudioDataStream(MD);

            MGP.start(loop);
            control_alarm_value=true;
     } catch (IOException e) {
            e.printStackTrace();
         }
     }
     
     public synchronized void stop(){
         try
	{
	   wait(2000);
           MGP.stop(loop);
            control_alarm_value=false;
	}
	catch (InterruptedException ie) {}
     }
}
